package main.leetcode.offer.secondround.from03to50;

import main.datastruc.ListNode;

import java.util.Stack;

/** 05.从尾到头打印链表 */
public class ex06 {
    public int[] reversePrint(ListNode head) {
        Stack<Integer> stack = new Stack<>();
        ListNode node = head;
        while (node != null) {
            stack.push(node.val);
            node = node.next;
        }
        int[] res = new int[stack.size()];
        for (int i = 0; i < res.length; ++i) {
            res[i] = stack.pop();
        }
        return res;
    }
}
